package com.easylinkin.linkappapi.lobar.controller;

import com.easylinkin.linkappapi.lobar.dto.UserProjectDTO;
import com.easylinkin.linkappapi.lobar.dto.app.AppUserGateDTO;
import com.easylinkin.linkappapi.lobar.dto.app.LobarUserDTO;
import com.easylinkin.linkappapi.lobar.service.LobarScreenService;
import com.easylinkin.linkappapi.lobar.service.UserClockService;
import io.swagger.annotations.Api;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

/**
 * @Author: kan yuanfeng
 * @Date: 2022/5/30 16:36
 * @Description: 劳务分析
 */
@RestController
@RequestMapping("lobarAnalysis")
@Api(tags = "劳务分析")
public class LobarAnalysisController {
  @Autowired
  private LobarScreenService lobarScreenService;
  @Autowired
  private UserClockService userClockService;

  /**
   * 出勤统计
   */
  @GetMapping("statistics")
  public RestMessage statistics() {
    List<AppUserGateDTO> result = lobarScreenService.statistics();
    return RestBuilders.successBuilder().data(result).build();
  }

  /**
   * 出勤分析
   */
  @GetMapping("analysis")
  public RestMessage analysis() {
    List<LobarUserDTO> list = lobarScreenService.analysisMonth();
    return RestBuilders.successBuilder().data(list).build();
  }

  /**
   * 查询班组今日考勤数据
   */
  @GetMapping("group")
  public RestMessage getGroup(){
    List<LobarUserDTO> lobarUserDTOS = userClockService.getGroupClock();
    List<LobarUserDTO> userDTOS = lobarUserDTOS.stream()
        .sorted(Comparator.comparing(LobarUserDTO::getIn).reversed())
        .collect(Collectors.toList());
    return RestBuilders.successBuilder().data(userDTOS).build();
  }

  /**
   * 按工种统计
   */
  @GetMapping("workType")
  public RestMessage getAttnByWorkType(){
    List<LobarUserDTO> list = lobarScreenService.getAttnByWorkType();
    return RestBuilders.successBuilder().data(list).build();
  }

  /**
   * 参建单位统计
   */
  @GetMapping("company")
  public RestMessage getByCompany(){
    List<AppUserGateDTO> list = lobarScreenService.getByCompany();
    return RestBuilders.successBuilder().data(list).build();
  }

  /**
   * 最新考勤
   */
  @GetMapping("newAttention")
  public RestMessage newAttention(){
    List<UserProjectDTO> list = lobarScreenService.newAttention();
    return RestBuilders.successBuilder().data(list).build();
  }

  /**
   * 最新进场
   */
  @GetMapping("newJoin")
  public RestMessage newJoin(){
    List<UserProjectDTO> list = lobarScreenService.newJoin();
    return RestBuilders.successBuilder().data(list).build();
  }
}
